<template>
  <div class="msgDiv likeCompany">
    <el-table
      :data="tableData"
      style="width: 100%"
      min-height="400"
      :border="true"
      :header-cell-style="{ background: '#F4F4F4', color: '#045DB9' }"
    >
      <el-table-column type="index" label="序号" width="50">
        <template slot-scope="scope">
          <div class="rowBtn" @click="goDetail(scope.row)">{{((currentPage - 1) * pageSize) + (scope.$index + 1)}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="companyName" label="企业名称">
        <template slot-scope="scope">
          <div class="rowBtn" @click="goDetail(scope.row)">{{scope.row.companyName}}</div>
        </template>
      </el-table-column>

      <el-table-column prop="contactsPerson" label="联系人" width="130">
        <template slot-scope="scope">
          <div class="rowBtn" @click="goDetail(scope.row)">{{scope.row.contactsPerson}}</div>
        </template>
      </el-table-column>

      <el-table-column prop="contactsPhone" label="联系电话" width="140">
        <template slot-scope="scope">
          <div class="rowBtn" @click="goDetail(scope.row)">{{scope.row.contactsPhone}}</div>
        </template>
      </el-table-column>

      <el-table-column prop="applyTime" label="申请时间" width="180">
        <template slot-scope="scope" v-if="scope.row.applyTime">
          <div class="rowBtn" @click="goDetail(scope.row)">
            {{
          scope.row.applyTime | format
          }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="79">
        <template slot-scope="scope">
          <span class="rowBtn" @click="goDetail(scope.row)" style="color:#088BE6;">查看</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20, 25, 30]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { getIntendedCompanyList } from '@/common/api/company.js'
export default {
  filters: {
    //转换时间
    format(val) {
      return moment(val).format('YYYY-MM-DD HH:mm:ss')
    },
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      total: 0,
      id: '',
      tableData: [],
      show: '',
      buildingName: ''
    }
  },
  methods: {
    async getMessage() {
      let res = await getIntendedCompanyList({
        buildingInfoId: this.id,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      })
      if (res.code == 200) {
        this.tableData = res.rows
        this.total = res.total
      }
    },
    goDetail(row) {
      this.$router.push({
        name: 'enterpriseDetail',
        query: { id: row.buildingIntendedUserId,companyId: this.id,buildingName: this.buildingName },
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val
      this.getMessage()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getMessage()
    },
  },
  mounted() {
    this.id = this.$route.query.id
    this.show = this.$route.query.type;
    this.buildingName = this.$route.query.name
    this.getMessage()
  },
}
</script>


<style scoped>
.msgDiv {
  margin: 40px 0;
}
.block {
  margin-top: 14px;
  text-align: right;
}
.rowBtn {
  cursor: pointer;
  margin-right: 12px;
  width: 100%;
  height: 100%;
}
</style>